package com.magi.core;

import java.util.Iterator;
import java.util.List;

public class ClassMetaData {
    public static class Field {
        private final String type;
        private final String name;


        public Field(String type, String name) {
            this.type = type;
            this.name = name;
        }

        public String getType() {
            return type;
        }

        public String getName() {
            return name;
        }
    }

    private final String name;
    private final List<Field> fields;

    public ClassMetaData(String name, List<Field> fields) {
        this.name = name;
        this.fields = fields;
    }

    private Field getField(String name) {
        for (Field f : this.fields) {
            if (f.getName().equals(name)) { return f; }
        }
        return null;
    }

    public List<Field> getFields() {
        return this.fields;
    }

    public Iterator<Field> getFieldsIterator() {
        return new Iterator<Field>() {
            private final List<Field> fields = ClassMetaData.this.fields;
            private int index = 0;
            @Override
            public boolean hasNext() {
                return index < fields.size();
            }

            @Override
            public Field next() {
                index += 1;
                return fields.get(index - 1);
            }
        };
    }

    public String getName() {
        return this.name;
    }
}